﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;

namespace Citrix.XaAdminMobile.Util
{
    /// <summary>
    /// Converts a boolean "use alternate" input flag to determine whether to return the default
    /// or the alternate data template. You must bind valid data templates to the <see cref="Default"/>
    /// and <see cref="Alternate"/> properties.
    /// </summary>
    [ValueConversion(typeof(bool), typeof(DataTemplate))]
    internal class DataTemplateToggleConverter : IValueConverter
    {
        /// <summary>
        /// The default data template to use.
        /// </summary>
        public DataTemplate Default { get; set; }

        /// <summary>
        /// The alternate data template to use.
        /// </summary>
        public DataTemplate Alternate { get; set; }

        /// <summary>
        /// Converts a boolean "use alternate" flag into a data template.
        /// </summary>
        /// <param name="useAlternate">True to use the alternate template, false to use the
        /// default template.</param>
        /// <param name="targetType">Not used.</param>
        /// <param name="parameter">Not used.</param>
        /// <param name="culture">Not used.</param>
        /// <returns>The appropriate data template.</returns>
        public object Convert(object useAlternate, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (useAlternate is bool)
            {
                return (bool)useAlternate ? Alternate : Default;
            }
            else
            {
                return Default;
            }
        }

        /// <summary>
        /// Not supported.
        /// </summary>
        /// <param name="value">Not used.</param>
        /// <param name="targetType">Not used.</param>
        /// <param name="parameter">Not used.</param>
        /// <param name="culture">Not used.</param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
